#include<iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
// #include <opencv2/nonfree/nonfree.hpp>
#include "opencv2/calib3d/calib3d.hpp"
// #include <highgui.h>  
#include <opencv2/opencv.hpp>  
#include<vector>
#include<cmath>
#include "opencv2/xfeatures2d.hpp"

int main(){
	//角点检测
    cv::Mat image_color = cv::imread("/media/st/Application/Ubuntu/dataset/tj/1019/img/1019/training/004000.jpg", cv::IMREAD_COLOR);
 
	//使用灰度图像进行角点检测
	cv::Mat image_gray;
	cv::cvtColor(image_color, image_gray, cv::COLOR_BGR2GRAY);
 
	//设置角点检测参数
	std::vector<cv::Point2f> corners;
	int max_corners = 200;
	double quality_level = 0.01;
	double min_distance = 3.0;
	int block_size = 3;
	bool use_harris = false;
	double k = 0.04;
 
	//角点检测
	cv::goodFeaturesToTrack(image_gray, 
							corners, 
							max_corners, 
							quality_level, 
							min_distance, 
							cv::Mat(), 
							block_size, 
							use_harris, 
							k);
 
	//将检测到的角点绘制到原图上
	for (int i = 0; i < corners.size(); i++)
	{
		cv::circle(image_color, corners[i], 1, cv::Scalar(0, 0, 255), 2, 8, 0);
	}

	//特征点描述子
	    // 创建SURF特征点变量
    cv::Ptr<cv::xfeatures2d::SURF> surf = cv::xfeatures2d::SURF::create(500, 4, 3, true, false);

    // 计算SURF关键点
    std::vector<cv::KeyPoint> keyPoints;
    surf->detect(image_color, keyPoints);

    // 计算SURF描述子
    cv::Mat descriptions;
    surf->compute(image_color, keyPoints, descriptions);

    // 绘制特征点
    cv::Mat srcCopy;
    image_color.copyTo(srcCopy);
    // 绘制不含角度和大小的结果
    cv::drawKeypoints(image_color, keyPoints, image_color, cv::Scalar(0, 0, 255));
    // 绘制含有角度的大小的结果
    cv::drawKeypoints(image_color, keyPoints, srcCopy, cv::Scalar(255, 0, 0), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);

    // 显示结果
    cv::imshow("不含角度和大小的结果", image_color);
    cv::imshow("含有角度和大小的结果", srcCopy);
    cv::waitKey(0);




	cv::imshow("house corner", image_color);
	cv::waitKey(0);
	return 0;
}